package com.sgb.kjwl.view.ui.fragment.enterprise;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Editable;
import android.text.InputFilter;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.util.Pair;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.bumptech.glide.Glide;
import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.config.PictureMimeType;
import com.luck.picture.lib.entity.LocalMedia;
import com.sgb.kjwl.AppFragment;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.FragmentCompanyAlreadyPublishBinding;
import com.sgb.kjwl.databinding.FragmentPropertyPublishBinding;
import com.sgb.kjwl.model.entity.enterprise.AssesTypeEntiy;
import com.sgb.kjwl.model.entity.enterprise.IpPickSelectEntity;
import com.sgb.kjwl.model.entity.enterprise.PublishPropertyDetailEntity;
import com.sgb.kjwl.model.entity.enterprise.PublishTradeDetailEntity;
import com.sgb.kjwl.utils.ActivityJump;
import com.sgb.kjwl.utils.KeyboardUtils;
import com.sgb.kjwl.utils.PickerHelper;
import com.sgb.kjwl.utils.PointUtils;
import com.sgb.kjwl.utils.UploadCheckHelper;
import com.sgb.kjwl.view.ui.activity.enterprise.MakeOverPublishActivity;
import com.sgb.kjwl.view.ui.activity.enterprise.MakeOverPublishMainActivity;
import com.sgb.kjwl.view.ui.activity.enterprise.PublishServiceActivity;
import com.sgb.kjwl.view.ui.adapter.enterprise.TextViewBindingAdapter;

import com.sgb.kjwl.view.ui.adapter.self.publish.ImageAdapter;
import com.sgb.kjwl.viewmodel.enterprise.PublishViewModel;
import com.swgk.core.recyclerview.adapter.AdapterOnItemClick;
import com.swgk.core.util.CheckUtils;
import com.swgk.core.util.DateUtils;
import com.swgk.core.util.MToast;
import com.swgk.core.util.SharedPreferenceUtil;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static android.app.Activity.RESULT_OK;

public class PropertyPublishFragment extends AppFragment {

    FragmentPropertyPublishBinding mBinding;
    PublishViewModel mViewModel;
    private String mOldOrNewId,mOldOrNewName,mTypeName,mTypeId,mTime,mId = "",mAssetsId = "",strBuyingPrice = "",strSalePrice="";
    PublishPropertyDetailEntity mEntity = null;
    OptionsPickerView<IpPickSelectEntity> mPropertyNewOrOldOptionsPickerView;
    OptionsPickerView<AssesTypeEntiy> mPropertyTypeOptionsPickerView;
    private MakeOverPublishActivity mActivity;
    private List<File> list = new ArrayList<>();
    boolean isChecked,isNeed;
    private ImageAdapter mImageAdapter;
    private List<String> urls = new ArrayList<>();
    private List<LocalMedia> selectList = new ArrayList<>();

    public static PropertyPublishFragment newInstance(){
        return new PropertyPublishFragment();
    }

    public static PropertyPublishFragment newInstance(PublishPropertyDetailEntity entity){
        PropertyPublishFragment tradePublishFragment = new PropertyPublishFragment();
        Bundle bundle = new Bundle();
        bundle.putSerializable("entity",entity);
        tradePublishFragment.setArguments(bundle);
        return tradePublishFragment;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_property_publish,container,false);
        return mBinding.getRoot();
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        mBinding.setLifecycleOwner(this);
        mViewModel = new ViewModelProvider(this).get(PublishViewModel.class);

        initCheckBox();
        initButton();
        initData();
    }

    private void initCheckBox(){

        mBinding.tvFragmentPropertyPublishNewOrOldTags.setVisibility(View.GONE);
        mBinding.tvFragmentTradePublishSelectNewOrOld.setVisibility(View.GONE);
        mBinding.ivFragmentPropertyPublishLine3.setVisibility(View.GONE);
        mBinding.rbFragmentPropertyPublishMakeoverSelectorPrice.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                isChecked = !isChecked;
                if (isChecked){
                    mBinding.ivYijia.setImageResource(R.mipmap.gouxuan_makeover_publish_price);
                    mBinding.etFragmentPropertyPublishMakeoverMuchEdit.setEnabled(false);
                    mBinding.etFragmentPropertyPublishMakeoverMuchEdit.setText("请输入价格");
                    mBinding.etFragmentPropertyPublishMakeoverMuchEdit.setTextColor(getResources().getColor(R.color.color_C0C4CC));
                }else {
                    mBinding.etFragmentPropertyPublishMakeoverMuchEdit.setEnabled(true);
                    mBinding.ivYijia.setImageResource(R.mipmap.weigouxuan_makeover_publish_price);
                    mBinding.etFragmentPropertyPublishMakeoverMuchEdit.setText("");
                    mBinding.etFragmentPropertyPublishMakeoverMuchEdit.setTextColor(getResources().getColor(R.color.FF000000));
                }
            }
        });
    }

    private void initButton(){
        mBinding.tvFragmentPropertyPublishSelectType.setOnClickListener(this);
        mBinding.tvFragmentTradePublishSelectNewOrOld.setOnClickListener(this);
        mBinding.tvFragmentTradePublishSelectBuyTime.setOnClickListener(this);
        mBinding.ivApplyTime.setOnClickListener(this);
    }

    @SuppressLint("SetJavaScriptEnabled")
    private void initData(){

        mImageAdapter = new ImageAdapter(getContext(), null, null, 6);
        mBinding.ivFragmentPropertyPublishUploadPicture.setLayoutManager(new GridLayoutManager(getContext(),4));
        mBinding.ivFragmentPropertyPublishUploadPicture.setAdapter(mImageAdapter);

        if (getArguments() != null){
            mEntity = (PublishPropertyDetailEntity) getArguments().getSerializable("entity");
        }

        if (mEntity!=null){
            mId = mEntity.getId() + "";
            mAssetsId = mEntity.getAssetsId();
            mOldOrNewId = mEntity.getAssetsNewAndOldId();
            mOldOrNewName = mEntity.getAssetsOldNew();
            mTypeName = mEntity.getTypeName();
            mTime = mEntity.getBuyingTime();
            strBuyingPrice = mEntity.getBuyingPrice() + "";
            strSalePrice= mEntity.getSalePrice() + "";

            mBinding.etFragmentPropertyPublishNameEdit.setText(mEntity.getAssetsName());
            mBinding.tvFragmentPropertyPublishSelectType.setText(mEntity.getTypeName());
            mBinding.tvFragmentTradePublishSelectNewOrOld.setText(mEntity.getAssetsOldNew());
            mBinding.tvFragmentPropertyPublishNewOrOldTags.setVisibility(TextUtils.isEmpty(mEntity.getAssetsOldNew())?View.GONE:View.VISIBLE);
            mBinding.tvFragmentTradePublishSelectNewOrOld.setVisibility(TextUtils.isEmpty(mEntity.getAssetsOldNew())?View.GONE:View.VISIBLE);
            mBinding.ivFragmentPropertyPublishLine3.setVisibility(TextUtils.isEmpty(mEntity.getAssetsOldNew())?View.GONE:View.VISIBLE);
            mBinding.tvFragmentTradePublishSelectBuyTime.setText(mEntity.getBuyingTime());
            mBinding.etFragmentPropertyPublishBuyPriceEdit.setText(mEntity.getBuyingPrice() == -2 ? "" : PointUtils.originalPrice(mEntity.getBuyingPrice()));

            isNeed = !TextUtils.isEmpty(mEntity.getAssetsOldNew());
            mTypeId = mEntity.getAssetsType();

            if (!"".equals(mBinding.etFragmentPropertyPublishBuyPriceEdit.getText().toString())){
                mBinding.ivApplyTime.setVisibility(View.VISIBLE);
            }

            if (mEntity.getSalePrice() == -1){
                isChecked = true;
                mBinding.ivYijia.setImageResource(R.mipmap.gouxuan_makeover_publish_price);
                mBinding.etFragmentPropertyPublishMakeoverMuchEdit.setEnabled(false);
                mBinding.etFragmentPropertyPublishMakeoverMuchEdit.setText("请输入价格");
                mBinding.etFragmentPropertyPublishMakeoverMuchEdit.setTextColor(getResources().getColor(R.color.color_C0C4CC));
            }else {
                mBinding.etFragmentPropertyPublishMakeoverMuchEdit.setEnabled(true);
                mBinding.ivYijia.setImageResource(R.mipmap.weigouxuan_makeover_publish_price);
                mBinding.etFragmentPropertyPublishMakeoverMuchEdit.setText(PointUtils.originalPrice(mEntity.getSalePrice()));
                mBinding.etFragmentPropertyPublishMakeoverMuchEdit.setTextColor(getResources().getColor(R.color.FF000000));
            }

            mBinding.etFragmentPropertyPublishLinkman.setText(mEntity.getLinkman());
            mBinding.tvFragmentPropertyPublishPhone.setText(mEntity.getContactNumber());

            String content = mEntity.getDetailedDescription();
            if (content != null && !"".equals(content)) {
                mBinding.webDescription.getSettings().setDefaultTextEncodingName("UTF-8");
                mBinding.webDescription.getSettings().setJavaScriptEnabled(true);//支持JS
                String js = "<script type=\"text/javascript\">" +
                        "var imgs = document.getElementsByTagName('img');" + // 找到img标签
                        "for(var i = 0; i<imgs.length; i++){" +  // 逐个改变
                        "imgs[i].style.width = '100%';" +  // 宽度改为100%
                        "imgs[i].style.height = 'auto';" +
                        "}" +
                        "</script>";
                mBinding.webDescription.loadDataWithBaseURL(null, content + js, "text/html", "UTF-8", null);
                mBinding.webDescription.setVisibility(View.VISIBLE);
                mBinding.emptyView.setVisibility(View.GONE);
            } else {
                mBinding.webDescription.setVisibility(View.GONE);
                mBinding.emptyView.setVisibility(View.VISIBLE);
            }

            String[] picture = mEntity.getCommodityImages().split(",");
            List<String> list = new ArrayList<>();
            if (!"".equals(picture[0])){
                Collections.addAll(list, picture);
            }

            mImageAdapter.setNetImgList(list);
        }

        mViewModel.queryPropertyType(getContext());
        mViewModel.getPropertyNewOrOldOption(getContext());

        mViewModel.mPropertyTypeListLiveData.observe(getViewLifecycleOwner(), new Observer<List<AssesTypeEntiy>>() {
            @Override
            public void onChanged(List<AssesTypeEntiy> assesTypeEntiys) {
                if (mPropertyTypeOptionsPickerView == null) {
                    mPropertyTypeOptionsPickerView = new OptionsPickerBuilder(getContext(), new OnOptionsSelectListener() {
                        @Override
                        public void onOptionsSelect(int options1, int options2, int options3, View v) {
                            mBinding.tvFragmentPropertyPublishSelectType.setText(assesTypeEntiys.get(options1).getClassificationName());
                            mTypeId = assesTypeEntiys.get(options1).getClassificationType() + "";
                            mTypeName = assesTypeEntiys.get(options1).getClassificationName();
                            isNeed = assesTypeEntiys.get(options1).getRelateOld() == 0;

                            if (isNeed){
                                mBinding.tvFragmentTradePublishSelectNewOrOld.setVisibility(View.VISIBLE);
                                mBinding.tvFragmentPropertyPublishNewOrOldTags.setVisibility(View.VISIBLE);
                                mBinding.ivFragmentPropertyPublishLine3.setVisibility(View.VISIBLE);
                            }else {
                                mBinding.tvFragmentTradePublishSelectNewOrOld.setVisibility(View.GONE);
                                mBinding.tvFragmentPropertyPublishNewOrOldTags.setVisibility(View.GONE);
                                mBinding.ivFragmentPropertyPublishLine3.setVisibility(View.GONE);
                            }
                        }
                    }).setCancelText("取消").setSubCalSize(15)
                            .setCancelColor(Color.parseColor("#666666"))
                            .setTitleColor(Color.parseColor("#969696")).setTitleSize(15)
                            .setSubmitText("确定")
                            .setSubmitColor(Color.parseColor("#5792FD"))
                            .setTextColorCenter(Color.parseColor("#ff333333"))
                            .setContentTextSize(15)
                            .setLineSpacingMultiplier(2.5f)
                            .setDividerColor(Color.parseColor("#EDEDED"))
                            .setDecorView(getActivity().getWindow().getDecorView().findViewById(android.R.id.content)).build();
                    mPropertyTypeOptionsPickerView.setPicker(assesTypeEntiys);
                    mPropertyTypeOptionsPickerView.setSelectOptions(0);

                }
                KeyboardUtils.hideSoftInput(getActivity());
            }
        });

        mViewModel.mPropertyOldOrNewListLiveData.observe(getViewLifecycleOwner(), new Observer<List<IpPickSelectEntity>>() {
            @Override
            public void onChanged(List<IpPickSelectEntity> ipPickSelectEntities) {
                if (mPropertyNewOrOldOptionsPickerView == null) {
                    mPropertyNewOrOldOptionsPickerView = new OptionsPickerBuilder(getContext(), new OnOptionsSelectListener() {
                        @Override
                        public void onOptionsSelect(int options1, int options2, int options3, View v) {
                            mBinding.tvFragmentTradePublishSelectNewOrOld.setText(ipPickSelectEntities.get(options1).getName());
                            mOldOrNewId = ipPickSelectEntities.get(options1).getId();
                            mOldOrNewName = ipPickSelectEntities.get(options1).getName();
                        }
                    }).setCancelText("取消").setSubCalSize(15)
                            .setCancelColor(Color.parseColor("#666666"))
                            .setTitleColor(Color.parseColor("#969696")).setTitleSize(15)
                            .setSubmitText("确定")
                            .setSubmitColor(Color.parseColor("#5792FD"))
                            .setTextColorCenter(Color.parseColor("#ff333333"))
                            .setContentTextSize(15)
                            .setLineSpacingMultiplier(2.5f)
                            .setDividerColor(Color.parseColor("#EDEDED"))
                            .setDecorView(getActivity().getWindow().getDecorView().findViewById(android.R.id.content)).build();
                    mPropertyNewOrOldOptionsPickerView.setPicker(ipPickSelectEntities);
                    mPropertyNewOrOldOptionsPickerView.setSelectOptions(0);
                }
                KeyboardUtils.hideSoftInput(getActivity());
            }
        });

        mActivity = (MakeOverPublishActivity) getActivity();

        mViewModel.mSaveSuccessProperty.observe(getViewLifecycleOwner(), new Observer<Boolean>() {
            @Override
            public void onChanged(Boolean aBoolean) {
//                getActivity().setResult(2);
                getActivity().finish();
                ActivityJump.jumpToActivity(getContext(), MakeOverPublishMainActivity.class, Pair.create("position", 3));
            }
        });

        mViewModel.uploadFileSuccess.observe(getViewLifecycleOwner(), new Observer<List<String>>() {
            @Override
            public void onChanged(List<String> list) {
                urls = list;
                urls.addAll(mImageAdapter.getNetUrls());
                upload();
            }
        });


    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mActivity.mLiveData.observe(getViewLifecycleOwner(), new Observer<Boolean>() {
            @Override
            public void onChanged(Boolean aBoolean) {
                if (aBoolean){
                    if (!UploadCheckHelper.textCheck(getContext(),new TextView[]{mBinding.etFragmentPropertyPublishNameEdit,mBinding.tvFragmentPropertyPublishSelectType,mBinding.tvFragmentTradePublishSelectNewOrOld
                                    ,mBinding.etFragmentPropertyPublishMakeoverMuchEdit,mBinding.etFragmentPropertyPublishLinkman,mBinding.tvFragmentPropertyPublishPhone}
                            ,new String[]{"资产名称","资产类型","资产新旧","价格","联系人姓名","联系电话"},isNeed)){
                        return;
                    }
                    if (!CheckUtils.isMobileForService(mBinding.tvFragmentPropertyPublishPhone.getText().toString().trim())) {
                        MToast.showToast(getContext(), "请输入正确的电话格式");
                        return;
                    }
                    if (mImageAdapter.getNetUrls().size() <= 0 && mImageAdapter.getFileList().size() <= 0 && list.size() <= 0){
                        MToast.showToast(getContext(),"请上传商品图片");
                        return;
                    }

                    if (mImageAdapter.getFileList().size() > 0){
                        mViewModel.uploadPicture(getContext(),mImageAdapter.getFileList());
                    }else {
                        urls.addAll(mImageAdapter.getNetUrls());
                        upload();
                    }
                }
            }
        });

        mActivity.mIntentLiveData.observe(getViewLifecycleOwner(), new Observer<Intent>() {
            @Override
            public void onChanged(Intent data) {
                // 图片、视频、音频选择结果回调
                selectList = PictureSelector.obtainMultipleResult(data);
                list.clear();
                urls.clear();
                for (LocalMedia localMedia : selectList) {
                    File file = new File(localMedia.getRealPath());
                    list.add(file);
                    urls.add(localMedia.getRealPath());
                }
                mImageAdapter.setDatas(selectList, urls);
                mImageAdapter.setFileList(list);
            }
        });
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()){
            case R.id.tv_fragment_property_publish_select_type:
                if (mPropertyTypeOptionsPickerView != null){
                    mPropertyTypeOptionsPickerView.show();
                }else {
                    mViewModel.queryPropertyType(getContext());
                }
                break;
            case R.id.tv_fragment_trade_publish_select_new_or_old:
                if (mPropertyNewOrOldOptionsPickerView != null){
                    mPropertyNewOrOldOptionsPickerView.show();
                }else {
                    mViewModel.getPropertyNewOrOldOption(getContext());
                }
                break;
            case R.id.tv_fragment_trade_publish_select_buy_time:
                PickerHelper.with(getContext()).getCommonTimeBuild("", new OnTimeSelectListener() {
                    @Override
                    public void onTimeSelect(Date date, View v) {
                        mTime = DateUtils.timestampToDate(date.getTime());
                        mBinding.tvFragmentTradePublishSelectBuyTime.setText(DateUtils.timestampToDate(date.getTime()));
                        mBinding.ivApplyTime.setVisibility(View.VISIBLE);
                    }
                }).setRangDate(null, Calendar.getInstance()).setCancelText("取消").setSubCalSize(15)
                        .setCancelColor(Color.parseColor("#666666"))
                        .setTitleColor(Color.parseColor("#969696")).setTitleSize(15)
                        .setSubmitText("确定")
                        .setSubmitColor(Color.parseColor("#5792FD"))
                        .setTextColorCenter(Color.parseColor("#ff333333"))
                        .setContentTextSize(15)
                        .setLineSpacingMultiplier(2.5f)
                        .setDividerColor(Color.parseColor("#EDEDED"))
                        .build().show();
                break;
            case R.id.iv_apply_time:
                mTime = "";
                mBinding.tvFragmentTradePublishSelectBuyTime.setText("");
                mBinding.ivApplyTime.setVisibility(View.GONE);
                break;
        }
    }

    public void upload(){
        StringBuilder stringBuilder = new StringBuilder();
        for (String s : urls) {
            stringBuilder.append(",").append(s);
        }
        /**
         * strBuyingTime	T文本	是
         * assetsOldNew	T文本	是
         * isDelete	T文本	是
         * status	T文本	是
         * label	T文本	是
         * contactNumber	T文本	是
         * linkman	T文本	是
         * detailedDescription	T文本	是
         * publishType	T文本	是
         * commodityImages	T文本	是
         * createUser	T文本	是
         * createTime	T文本	是
         * updateUser	T文本	是
         * updateTime	T文本	是
         * selfEmployed	T文本	是
         * comType	T文本	是
         * assetsNewAndOldId	T文本	是
         * teamNo	T文本	是
         */
        String companyNo = "";
        String teamNo = "";
        String user = "";
        if (SharedPreferenceUtil.getInstance().getSaveIntData(SharedPreferenceUtil.COM_TYPE,0) == 1){
            companyNo = SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.COMPANY_NO,"");
        }else if (SharedPreferenceUtil.getInstance().getSaveIntData(SharedPreferenceUtil.COM_TYPE,0) == 2){
            teamNo = SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.COMPANY_NO,"");
        }else {
            user = SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.USER_NO,"");
        }

        Map<String,Object> map = new HashMap<>();
        map.put("id",mId);
        map.put("assetsType",mTypeId);
        map.put("imgList",stringBuilder.delete(0,1).toString());
        map.put("buyingTime",mTime);
        map.put("companyNo",companyNo);
        map.put("userNo",user);
        map.put("contactNumber",mBinding.tvFragmentPropertyPublishPhone.getText().toString());
        map.put("linkman",mBinding.etFragmentPropertyPublishLinkman.getText().toString());
//        map.put("detailedDescription",mBinding.etFragmentPropertyPublishDescription.getText().toString());
        map.put("salePrice",mBinding.etFragmentPropertyPublishMakeoverMuchEdit.getText().toString().equals("请输入价格")?"-1":mBinding.etFragmentPropertyPublishMakeoverMuchEdit.getText().toString());
        map.put("assetsNewAndOldId",isNeed ? mOldOrNewId : "");
        map.put("assetsName",mBinding.etFragmentPropertyPublishNameEdit.getText().toString());
        map.put("price",mBinding.etFragmentPropertyPublishMakeoverMuchEdit.getText().toString().equals("请输入价格")?"-1":mBinding.etFragmentPropertyPublishMakeoverMuchEdit.getText().toString());
        map.put("publishType",SharedPreferenceUtil.getInstance().getSaveIntData(SharedPreferenceUtil.COM_TYPE,0));
        map.put("assetsOldNew",isNeed ? mOldOrNewName : "");
        if (SharedPreferenceUtil.getInstance().getSaveIntData(SharedPreferenceUtil.COM_TYPE,0) == 0) {
            map.put("realName",SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.REAL_NAME,""));
        } else {
            map.put("realName", SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.COMPANY_NAME, ""));
        }
        map.put("buyingPrice",mBinding.etFragmentPropertyPublishBuyPriceEdit.getText().toString());
        map.put("teamNo", teamNo);
        map.put("phone", SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.LOGIN_PHONE, ""));
        map.put("assetsId",mAssetsId);
        map.put("commodityImages",stringBuilder.toString());
        map.put("strBuyingPrice",strBuyingPrice);
        map.put("strSalePrice",strBuyingPrice);
        map.put("typeName",mBinding.tvFragmentPropertyPublishSelectType.getText().toString());
        if (mEntity != null) {
            mViewModel.updateProperty(getContext(), map);
        }else {
            mViewModel.saveProperty(getContext(),map);
        }
    }

}
